package com.yuki.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.yuki.api.dto.UmsAdminLoginParam;
import com.yuki.api.model.UmsAdmin;
import com.yuki.api.service.IUserService;
import jdk.nashorn.internal.parser.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.yuki.provider.mapper.UmsAdminMapper;

/**
 * @description:
 * @author: Yuki Tadayoshi
 * @time: 2021/3/24 17:31
 */
@Service(
        version = "1.0.0",
        interfaceName = "com.yuki.api.service.IUserService",
        interfaceClass = IUserService.class
)
@Transactional
public class UserServiceImpl implements IUserService {

    @Autowired
    private UmsAdminMapper dao;

    @Autowired
    private TokenServiceImpl tokenService;

    @Override
    public UmsAdmin login(UmsAdminLoginParam user) {
        return null;
    }

    @Override
    public UmsAdmin findUserById(Long userId) {
        return dao.selectByPrimaryKey(userId);
    }

    @Override
    public UmsAdmin findByUsername(String username) {
        UmsAdmin admin = dao.selectByUsername(username);
        return admin;
    }

    @Override
    public UmsAdmin reg(UmsAdmin user) {
        dao.insert(user);
        return user;
    }

    @Override
    public UmsAdmin findByUmsAdmin(String token) {
        String userId = tokenService.getUserId(token);
        return this.findUserById(Long.parseLong(userId));
    }
}
